<template>
  <div>
    <router-view :key="$route.fullPath"></router-view>

    <van-tabbar v-model="active" :placeholder="true">
      <van-tabbar-item name="home" icon="home-o" @click="gotoIndex"
        >首页</van-tabbar-item
      >
      <van-tabbar-item name="search" icon="search" @click="gotoSearch"
        >搜索</van-tabbar-item
      >
      <!-- <van-tabbar-item
        name="cart"
        icon="cart-o"
        :badge="cartNum == 0 ? '' : cartNum"
        @click="gotoCart"
      >
        购物车</van-tabbar-item
      > -->
      <van-tabbar-item
        name="cart"
        icon="cart-o"
        :badge="num == 0 ? '' : num"
        @click="gotoCart"
      >
        购物车</van-tabbar-item
      >

      <van-tabbar-item name="star" icon="star-o" @click="gotoCollect"
        >收藏</van-tabbar-item
      >
      <van-tabbar-item name="friends" icon="user-o" @click="gotoPerson"
        >我的</van-tabbar-item
      >
    </van-tabbar>
  </div>
</template>
<script setup>
import { onMounted, ref } from "vue";
import { useRouter } from "vue-router";
import { showDialog } from "vant";
import { userStore } from "../store/piniaStore";
import { storeToRefs } from "pinia";
const useUserStore = userStore();
const router = useRouter();
// 失去响应性
// let cartNum = useUserStore.cartNum;
// let num = useUserStore.num;
const { num, cartNum } = storeToRefs(useUserStore);

let active = ref("home");

function gotoIndex() {
  router.push("index");
}
function gotoSearch() {
  router.push("search");
}
function gotoCart() {
  router.push("cart");
}
function gotoPerson() {
  router.push("person");
}
function gotoCollect() {
  router.push("collect");
}
</script>
